package com.ruoyi.web.controller.equ;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.equ.domain.EquIcont;
import com.ruoyi.equ.service.IEquIcontService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import jakarta.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 系统控制Controller
 *
 * @author ruoyi
 * @date 2025-11-05
 */
@RestController
@RequestMapping("/equ/icont")
public class EquIcontController extends BaseController
{
    @Autowired
    private IEquIcontService equIcontService;

    /**
     * 查询系统控制列表
     */
    @PreAuthorize("@ss.hasPermi('equ:icont:list')")
    @GetMapping("/list")
    public TableDataInfo list(@ModelAttribute EquIcont equIcont)
    {
        startPage();
        List<EquIcont> list = equIcontService.selectEquIcontList(equIcont);
        return getDataTable(list);
    }

    /**
     * 导出系统控制列表
     */
    @PreAuthorize("@ss.hasPermi('equ:icont:export')")
    @Log(title = "系统控制", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @ModelAttribute EquIcont equIcont)
    {
        List<EquIcont> list = equIcontService.selectEquIcontList(equIcont);
        ExcelUtil<EquIcont> util = new ExcelUtil<EquIcont>(EquIcont.class);
        util.exportExcel(response, list, "系统控制数据");
    }

    /**
     * 获取系统控制详细信息
     */
    @PreAuthorize("@ss.hasPermi('equ:icont:query')")
    @GetMapping(value = "/{iconId}")
    public AjaxResult getInfo(@PathVariable("iconId") Long iconId)
    {
        return success(equIcontService.selectEquIcontByIconId(iconId));
    }

    /**
     * 新增系统控制
     */
    @PreAuthorize("@ss.hasPermi('equ:icont:add')")
    @Log(title = "系统控制", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EquIcont equIcont)
    {
        return toAjax(equIcontService.insertEquIcont(equIcont));
    }

    /**
     * 修改系统控制
     */
    @PreAuthorize("@ss.hasPermi('equ:icont:edit')")
    @Log(title = "系统控制", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EquIcont equIcont)
    {
        return toAjax(equIcontService.updateEquIcont(equIcont));
    }

    /**
     * 删除系统控制
     */
    @PreAuthorize("@ss.hasPermi('equ:icont:remove')")
    @Log(title = "系统控制", businessType = BusinessType.DELETE)
	@DeleteMapping("/{iconIds}")
    public AjaxResult remove(@PathVariable("iconIds") Long[] iconIds)
    {
        return toAjax(equIcontService.deleteEquIcontByIconIds(iconIds));
    }
    /**
     * 获取使用中的icon
     */
    @Anonymous
    @GetMapping("/getUsedIcont")
    public AjaxResult getUsedIcont()
    {
        return success(equIcontService.selectUsedEquIcont());
    }
}
